package com.eric.code.oauth2.app;

import com.eric.code.oauth2.common.BaseService;
import com.eric.code.oauth2.model.App;
import com.eric.code.oauth2.tools.UUIDKit;
import com.jfinal.plugin.activerecord.Page;

import java.util.Date;

/**
 * Created by eric on 17-3-23.
 */
public class AppService extends BaseService{

    public static final AppService me = new AppService();
    private final App dao = new App().dao();

    public Page<App> paginate(int pageNumber, int pageSize) {
        return dao.paginate(pageNumber, pageSize, "select * ", "from oauth2_client order by createAt desc");
    }

    public Page<App> paginate(int pageNumber) {
        return dao.paginate(pageNumber, PAGE_SIZE, "select * ", "from oauth2_client order by createAt desc");
    }



    /**
     * 初始化默认密码 123456
     * @param app
     */
    public void save(App app){
        app.setCreateAt(new Date());
        app.setClientId(UUIDKit.stringUUID());
        app.setClientSecret(UUIDKit.stringUUID());
        app.save();
    }

    public void delete(long appId){
        dao.deleteById(appId);
    }
}
